﻿using DataDoc.App.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataDoc.App.Data
{
    public class DocContext
    {
        public DocContext() 
        { 

        }

        /// <summary>
        /// 获取数据库连接字符串
        /// </summary>
        /// <returns></returns>
        public static string Connection()
        {
            IniFileHelper iniFile = new IniFileHelper(Application.StartupPath + "\\config.ini");
            string connection = iniFile.GetString("DOC", "CONNECTION", "");
            string dbIP = iniFile.GetString("DOC", "DB_IP", "");
            string dbName = iniFile.GetString("DOC", "DB_NAME", "");
            string charset = iniFile.GetString("DOC", "DB_CHARSET", "");
            string account = iniFile.GetString("DOC", "DB_ACCOUNT", "");
            string password = iniFile.GetString("DOC", "DB_PASSWORD", "");
            string db_info = "Server=" + dbIP + "; Database=" + dbName + "; Uid=" + account + "; Pwd=" + password + "; CharSet=" + charset;

            if (!string.IsNullOrEmpty(connection))
            {
                db_info = connection;
            }

            return db_info;
        }
    }
}
